package com.comm.dao.imp;

import com.comm.entity.ExpressCompany;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExpressCompanyDao extends SqlMapClientDaoSupport {

    public List<ExpressCompany> getAll() {
        return getSqlMapClientTemplate().queryForList("ExpressCompany.getAll");
    }

    public ExpressCompany getExpressCompanyByKey(Long id) {
        Map<String, Object> params = new HashMap<String, Object>(1, 1);
        params.put("id", id);
        return (ExpressCompany) getSqlMapClientTemplate().queryForObject(
                "ExpressCompany.getExpressCompanyByKey", params);
    }

    /**
     * 根据主键批量查找
     */
    public List<ExpressCompany> getExpressCompanyByKeys(List<Long> idList) {
        Map<String, Object> params = new HashMap<String, Object>(1, 1);
        params.put("keys", idList);
        return (List<ExpressCompany>) getSqlMapClientTemplate().queryForList("ExpressCompany.getExpressCompanysByKeys", params);
    }

    public ExpressCompany getExpressCompanyByCode(String code) {
        Map<String, Object> params = new HashMap<String, Object>(1, 1);
        params.put("code", code);
        return (ExpressCompany) getSqlMapClientTemplate().queryForObject("ExpressCompany.getExpressCompanyByCode", params);
    }

    public List<ExpressCompany> getExpressCompanyByCodes(List<String> codes) {
        Assert.notEmpty(codes, "codes不能为空");
        Map<String, Object> params = new HashMap<>(1, 1);
        params.put("codes", codes);
        return (List<ExpressCompany>) getSqlMapClientTemplate().queryForList("ExpressCompany.getExpressCompanyByCodes", params);
    }

    /**
     * 根据主键删除
     *
     * @return
     */
    public Integer deleteByKey(Integer id) {
        Map<String, Object> params = new HashMap<String, Object>(1, 1);
        params.put("id", id);
        return getSqlMapClientTemplate().delete("ExpressCompany.deleteByKey", params);
    }

    /**
     * 根据主键批量删除
     *
     * @return
     */
    public Integer deleteByKeys(List<Integer> idList) {
        Map<String, Object> params = new HashMap<String, Object>(1, 1);
        params.put("keys", idList);
        return getSqlMapClientTemplate().delete("ExpressCompany.deleteByKeys", params);
    }

    /**
     * 根据主键更新
     *
     * @return
     * @throws java.sql.SQLException
     */
    public Integer updateExpressCompanyByKey(ExpressCompany expressCompany) {
        return getSqlMapClientTemplate().update("ExpressCompany.updateExpressCompanyByKey", expressCompany);
    }

    public Integer truncate() {
        return getSqlMapClientTemplate().delete("ExpressCompany.truncate");
    }

}